<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tab-list {
            list-style: none;
            padding: 0;
            margin: 0;
            display: flex;
        }

        .tab-list li {
            width: 120px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            background: yellowgreen;
        }

        .tab-list li.active {
            background: grey;
        }

        .content-item {
            width: 480px;
            height: 150px;
            border: 2px solid #ddd;
        }

    </style>
</head>
<body>
<div id="app">
    <ul class="tab-list">
        <li
            @click="tabClick(index)"
            :class="{active: currentIndex === index}"
            v-for="(item, index) in tabList">{{item}}</li>
    </ul>

    <div
        class="content-item"
        v-show="currentIndex === index"
        v-for="(item, index) in contentList">{{item}}</div>
</div>

<script src="../20211018/vue.js"></script>
<script>
    let myApp = new Vue({
        el: '#app',
        data: {
            currentIndex: 0,
            tabList: ['国内新闻', '国际新闻', '体育新闻', '娱乐新闻'],
            contentList: ['这是第一个content内容','这是第二个content内容','这是第三个content内容','这是第四个content内容']
        },
        methods: {
            tabClick (index) {
                this.currentIndex = index
                console.log(index)
            }
        }
    })
</script>


</body>
</html>